<template>
	<view class="custom-navbar" :style="{ height: statusBarHeight + navBarHeight + 'px' }">
		<view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
		<view class="navbar-content">
			<view v-if="showBack" class="back-icon" @click="goBack">
				<u-icon name="arrow-left" size="20" color="#333"></u-icon>
			</view>
			<view class="search-box" @click="goToSearch">
				<u-icon name="search" size="16" color="#909399"></u-icon>
				<text class="placeholder">搜索商品</text>
			</view>
			<view class="right-icons">
				<view class="icon-item">
					<!-- <u-icon name="more-dot-fill" size="24" color="#333"></u-icon> -->
				</view>
				<view class="icon-item">
					<!-- <u-icon name="camera" size="24" color="#333"></u-icon> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'CustomNavbar',
		props: {
			title: {
				type: String,
				default: '商城'
			},
			showBack: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				statusBarHeight: 20,
				navBarHeight: 44
			}
		},
		created() {
			// 获取状态栏高度
			const systemInfo = uni.getSystemInfoSync();
			console.log(systemInfo);
			this.statusBarHeight = systemInfo.statusBarHeight;
			this.navBarHeight = 44; // 固定导航栏高度
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			goToSearch() {
				uni.navigateTo({
					url: '/subPack/search/search'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.custom-navbar {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 999;
		background-color: #ffffff;
		// box-shadow: 0 1px 6px rgba(0, 0, 0, 0.05);

		.status-bar {
			width: 100%;
		}

		.navbar-content {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 44px;
			padding: 0 10px;

			.back-icon {
				padding: 10px;
				margin-right: 5px;
				margin-left: -10px;
			}

			.search-box {
				flex: 1;
				display: flex;
				align-items: center;
				height: 32px;
				background-color: #f5f5f5;
				border-radius: 16px;
				padding: 0 12px;
				margin-right: 10px;

				.placeholder {
					color: #909399;
					font-size: 14px;
					margin-left: 5px;
				}
			}

			.right-icons {
				display: flex;
				align-items: center;

				.icon-item {
					width: 40px;
					height: 40px;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}
	}
</style>